package com.caipin.utils;

/**
 * @Author: zhunian0322@163.com
 * @DateTime: 2020-03-22 9:01
 * @Description: TODO
 */
public class ImsiConvertUtils {

    public static String toServiceProvider(String imsi) {
        String serviceProvider = "";

        if (imsi == null || imsi.length() < 15) {
            return serviceProvider;
        }

        if (imsi.charAt(0) == '4' && imsi.charAt(1) == '6' && imsi.charAt(2) == '0') { // 中国  MCC 为460
            StringBuilder sb = new StringBuilder();
            sb.append("中国");

            /**
             *  01 06 09 联通
             *  03 05 11 电信
             *  20 铁通
             *  00 02 07 08 移动
             */
            if (imsi.charAt(3) == '0') {
                if (imsi.charAt(4) == '1' || imsi.charAt(4) == '6' || imsi.charAt(4) == '9') {
                    sb.append("联通");
                } else if (imsi.charAt(4) == '0' || imsi.charAt(4) == '2' || imsi.charAt(4) == '7' || imsi.charAt(4) == '8') {
                    sb.append("移动");
                } else if (imsi.charAt(4) == '3' || imsi.charAt(4) == '5') {
                    sb.append("电信");
                }
            } else if (imsi.charAt(3) == '1' && imsi.charAt(4) == '1') {
                sb.append("电信");
            } else if (imsi.charAt(3) == '2' && imsi.charAt(4) == '0') {
                sb.append("铁通");
            } else {
                return "";
            }

            serviceProvider = sb.toString();
        }

        return serviceProvider;
    }

    public static Integer toServiceProviderNumber(String imsi) {
        Integer serviceProvider = 0;

        if (imsi == null || imsi.length() < 15) {
            return serviceProvider;
        }

        if (imsi.charAt(0) == '4' && imsi.charAt(1) == '6' && imsi.charAt(2) == '0') { // 中国  MCC 为460
            StringBuilder sb = new StringBuilder();
            sb.append("中国");

            /**
             *  01 06 09 联通
             *  03 05 11 电信
             *  20 铁通
             *  00 02 07 08 移动
             */
            if (imsi.charAt(3) == '0') {
                if (imsi.charAt(4) == '1' || imsi.charAt(4) == '6' || imsi.charAt(4) == '9') {
                    serviceProvider = 2;
                } else if (imsi.charAt(4) == '0' || imsi.charAt(4) == '2' || imsi.charAt(4) == '7' || imsi.charAt(4) == '8') {
                    serviceProvider = 1;
                } else if (imsi.charAt(4) == '3' || imsi.charAt(4) == '5') {
                    serviceProvider = 3;
                }
            } else if (imsi.charAt(3) == '1' && imsi.charAt(4) == '1') {
                serviceProvider = 3;
            } else if (imsi.charAt(3) == '2' && imsi.charAt(4) == '0') {
                serviceProvider = 3;
            }
        }

        return serviceProvider;
    }

    public static String toMobilePhoneNumberHead(String imsi) {
        String mobilePhoneNumberHead = "";
        if (imsi == null || imsi.length() < 15) {
            return mobilePhoneNumberHead;
        }

        StringBuilder sb = new StringBuilder();
        if (imsi.charAt(0) == '4' && imsi.charAt(1) == '6' && imsi.charAt(2) == '0') {  // 中国  MCC 为460
            if (imsi.charAt(3) == '0') {
                if (imsi.charAt(4) == '1' || imsi.charAt(4) == '6' || imsi.charAt(4) == '9') {
                    if (imsi.charAt(4) == '9') {
                        sb.append("176");
                    } else {
                        if (imsi.charAt(9) == '0' || imsi.charAt(9) == '1') {
                            sb.append("130");
                        } else if (imsi.charAt(9) == '2') {
                            sb.append("132");
                        } else if (imsi.charAt(9) == '3') {
                            sb.append("156");
                        } else if (imsi.charAt(9) == '4') {
                            sb.append("155");
                        } else if (imsi.charAt(9) == '5') {
                            sb.append("185");
                        } else if (imsi.charAt(9) == '6') {
                            sb.append("186");
                        } else if (imsi.charAt(9) == '7') {
                            sb.append("136");
                        } else if (imsi.charAt(9) == '9') {
                            sb.append("131");
                        }
                    }

                    sb.append(imsi.charAt(8)).append(imsi.charAt(5)).append(imsi.charAt(6)).append(imsi.charAt(7));
                } else if (imsi.charAt(4) == '0' && imsi.charAt(4) == '2' && imsi.charAt(4) == '7' && imsi.charAt(4) == '8') {
                    if (imsi.charAt(4) == '0') {
                        sb.append(13);
                        if (imsi.charAt(8) == '0' || imsi.charAt(8) == '1' || imsi.charAt(8) == '2' || imsi.charAt(8) == '3' || imsi.charAt(8) == '4') {
                            sb.append(imsi.charAt(8) - '0' + 5);
                            sb.append(imsi.charAt(9)).append(imsi.charAt(5)).append(imsi.charAt(6)).append(imsi.charAt(7));
                        } else if (imsi.charAt(8) == '5' || imsi.charAt(8) == '6' || imsi.charAt(8) == '7' || imsi.charAt(8) == '8' || imsi.charAt(8) == '9') {
                            sb.append(imsi.charAt(8)).append(imsi.charAt(0)).append(imsi.charAt(5)).append(imsi.charAt(6)).append(imsi.charAt(7));
                        }
                    } else if (imsi.charAt(4) == '2') {
                        if (imsi.charAt(5) == '0') {
                            sb.append(134);
                        } else if (imsi.charAt(5) == '1') {
                            sb.append(151);
                        } else if (imsi.charAt(5) == '2') {
                            sb.append(152);
                        } else if (imsi.charAt(5) == '3') {
                            sb.append(150);
                        } else if (imsi.charAt(5) == '4') {
                            sb.append(184);
                        } else if (imsi.charAt(5) == '5') {
                            sb.append(183);
                        } else if (imsi.charAt(5) == '6') {
                            sb.append(182);
                        } else if (imsi.charAt(5) == '7') {
                            sb.append(187);
                        } else if (imsi.charAt(5) == '8') {
                            sb.append(158);
                        } else if (imsi.charAt(5) == '9') {
                            sb.append(159);
                        }

                        sb.append(imsi.charAt(6)).append(imsi.charAt(7)).append(imsi.charAt(8)).append(imsi.charAt(9));
                    } else if (imsi.charAt(4) == '7') {
                        if (imsi.charAt(5) == '5') {
                            sb.append(178);
                        } else if (imsi.charAt(5) == '7') {
                            sb.append(157);
                        } else if (imsi.charAt(5) == '8') {
                            sb.append(188);
                        } else if (imsi.charAt(5) == '9') {
                            sb.append(147);
                        }

                        sb.append(imsi.charAt(6)).append(imsi.charAt(7)).append(imsi.charAt(8)).append(imsi.charAt(9));
                    }
                }

                mobilePhoneNumberHead = sb.toString();
            }


        }

        return mobilePhoneNumberHead;
    }

    public static String toNetWorkType(int cellNumber) {
        String netWorkType = null;

        switch (cellNumber) {
            case 1:
            case 2:
            case 3: {
                netWorkType = "TDD-LTE";
            }
            break;


            case 4:
            case 5:
            case 6:
            case 7: {
                netWorkType = "FDD-LTE";
            }
            break;

            case 8:
            case 9: {
                netWorkType = "GSM";
            }
            break;

            case 10: {
                netWorkType = "CDMA";
            }
            break;

            case 11: {
                netWorkType = "WCDMA";
            }
            break;

            case 12: {
                netWorkType = "TDSCDMA";
            }
            break;

            case 13: {
                netWorkType = "WIFI";
            }
            break;
        }

        return netWorkType;
    }

    public static Integer toNetWorkTypeNumber(int cellNumber) {
        Integer netWorkType = null;

        switch (cellNumber) {
            case 1:
            case 2:
            case 3: {
                netWorkType = 5;
            }
            break;


            case 4:
            case 5:
            case 6:
            case 7: {
                netWorkType = 6;
            }
            break;

            case 8:
            case 9: {
                netWorkType = 1;
            }
            break;

            case 10: {
                netWorkType = 4;
            }
            break;

            case 11: {
                netWorkType = 2;
            }
            break;

            case 12: {
                netWorkType = 3;
            }
            break;

            case 13: {
                netWorkType = 7;
            }
            break;
        }

        return netWorkType;
    }

    public static String toBand(int cellNumber){
        String bandStr = "";

        switch (cellNumber){
            case 1:
            {
                bandStr = "band38";
            }
            break;

            case 2:
            {
                bandStr = "band39";
            }
            break;

            case 3:
            {
                bandStr = "band40";
            }
            break;

            case 6:
            case 7:
            {
                bandStr = "band3/band1";
            }
            break;
        }

        return bandStr;
    }
}
